home *** CD-ROM | disk | FTP | other *** search
/ Univers Interactif 3 / INTERACTIF.BIN / pc / planeten / internet / macslip2.6up / MacSLIP Folder / sample.script < prev    next >
Text File  |  1995-01-11  |  8KB  |  318 lines

  1. #
  2. # Sample.script
  3. #
  4. # This is a generic script for logging into a SLIP server
  5. # You may need to modify it to work with your SLIP server or
  6. # use one of the more specific scripts.
  7. #
  8. # This script is designed to dial a Hayes compatible modem.
  9. #
  10. # The first time this script runs, it will prompt for your username,
  11. # password, and phone number to dial. These settings will be saved
  12. # for subequent connections.
  13. #
  14. # Using default settings, the modem will be initialized before this script
  15. # starts running. Make sure the "Init modem when connecting" option
  16. # is set in the "Modem" menu and that you have made an appropriate
  17. # modem selection.
  18. #
  19. ignore var busygo
  20.  
  21. # If user is not defined, ask for it.
  22. ifdef user goto skipuser
  23. message ""
  24. message "\bEnter your login username."
  25. ask var
  26. define user "$var"
  27. label skipuser
  28.  
  29. # if password is not defined, ask for it
  30. ifdef password goto skippass
  31. message "Will login to SLIP server as $user.\n\bPassword:"
  32. askp var
  33. define /h password "$var"
  34. label skippass
  35.  
  36. # if phone is not defined, ask for it
  37. ifdef phone goto skipphone
  38. message "\bEnter the phone number to dial"
  39. ask var
  40. define phone "$var"
  41. label skipphone
  42.  
  43. # Let the user know we're starting up
  44. label startup
  45. message "Script starting..."
  46. # Setup action handlers
  47. on restart goto restart
  48. on abort goto abort
  49.  
  50. # Dial the phone and wait for the terminal server to send its login
  51. # banner. Some areas support using *70 as a dialing prefix to suppress
  52. # call-waiting tones which will probably cause your modem
  53. # to lose the connection. Some terminal servers may require you to
  54. # autobaud before they will respond. Allow enough time for the modem
  55. # handshake to complete.
  56.  
  57. label dial
  58.  
  59. ifdef INITMODEM goto skipwarn
  60. beep
  61. message "\bYou should select a modem using Configure"
  62. label skipwarn
  63.  
  64. message "Dialing $phone..."
  65. flush
  66. on abort goto hangupabort
  67. send "ATDT $phone\r"
  68. {
  69.     ifmatch "name:" break
  70.     ifmatch "ogin:" break
  71.     ifmatch "NO DIALTONE" goto nodialtone
  72.     ifmatch "NO DIAL TONE" goto nodialtone
  73.     ifmatch "BUSY" goto phonebusy
  74.     ifmatch "NO CARRIER" goto nocarrier
  75.     iftime 1:15 goto dialtimeout
  76. }
  77.  
  78. # Log into the SLIP server. Try three times to send the username. Use
  79. # counter #1 to count the number of login attempts.
  80.  
  81. setcount 1 0
  82. label login
  83. ifcountgt 1 3 goto cantlogin
  84. message "Logging in as $user..."
  85. setcount 0 0
  86. label user
  87. flush
  88. ifcountgt 0 3 goto baduser
  89. send "$user\r"
  90. {
  91.     ifmatch "ssword:" break
  92.     ifmatch "name:" goto user
  93.     ifmatch "ogin:" goto user
  94.     iftime 10 goto baduser
  95. }
  96.  
  97. # Send the password and wait for the prompt. If we see the
  98. # username prompt again, then we didn't get logged in so try again.
  99.  
  100. message "Sending password..."
  101. flush
  102. send "$password\r"
  103. {
  104.     ifmatch ">" goto setslip
  105.     ifmatch "%" goto setslip
  106.     ifmatch "Access denied" goto accessdenied
  107.     ifmatch "incorrect" goto accessdenied
  108.     iftime 10 goto cantlogin
  109. }
  110.  
  111. # If the login attempt fails, we land here.
  112.  
  113. label accessdenied
  114. {
  115.     ifmatch "name:" goto login
  116.     ifmatch "ogin:" goto login
  117.     ifmatch "NO CARRIER" goto cantlogin
  118.     iftime 10 goto cantlogin
  119. }
  120.  
  121. # NOTE: You may wish to issue additional commands here before
  122. # enabling SLIP on your server.
  123.  
  124. # Enable SLIP.
  125. # In this generic script, you may have to issue a different command
  126. # here for your script server. Here, we just send "slip\r". You may
  127. # also need to match something other than "SLIP" to detect
  128. # that your slip command succeeded.
  129.  
  130. label setslip
  131. message "Enabling SLIP mode on server..."
  132. flush
  133. send "slip\r"
  134. # Use the following line instead for a Cisco terminal server
  135. # send "slip default\r"
  136. # Your slip server may also require you to specify an address:
  137. # send "slip 10.2.3.4\r"
  138. {
  139.     ifmatch "SLIP" break
  140.     ifmatch "beginning" break
  141.     ifmatch "start" break
  142.     iftime 10 goto cantstartslip
  143. }
  144.  
  145. # Uncomment one of the following "ipfind" lines if your server doesn't 
  146. # support BOOTP, but outputs your IP address in its response to 
  147. # the slip command. To uncomment the line, delete the leading
  148. # hashmark and space: "# "
  149. #
  150. # Uncomment the following line if your server only outputs the
  151. # your IP address. ex: "Slip connection to 10.2.3.4 beginning".
  152. # ipfind IPADDRESS
  153. # Uncomment the following line if your server outputs both, 
  154. # ex: "Slip session from 10.2.3.1 to 10.2.3.4 beginning"
  155. # ipfind IPGWADDRESS IPADDRESS
  156. # Uncomment this line if your server doesn't display the
  157. # gateway address as in the first ipfind command, or if 
  158. # your gateway address and your IP address aren't on the same subnet. 
  159. # set IPGWADDRESS $IPADDRESS
  160.  
  161. # All done.  Send message to alert the user, flush the junk out of the
  162. # receive buffer, and return success.
  163.  
  164. message "Script complete"
  165. flush
  166. return 1
  167.  
  168. # Error handlers.
  169.  
  170. label abort
  171. beep
  172. message "\bCommand-. seen or Cancel button clicked."
  173. goto aborted
  174.  
  175. label hangupabort
  176. beep
  177. message "\bCommand-. seen or Cancel button clicked."
  178. goto hangup
  179.  
  180. label cantfindmodem
  181. beep
  182. message "\bThe modem didn't respond to attention"
  183. message "\bbsignal.  Check modem and cabling."
  184. goto aborted
  185.  
  186. label cantinitmodem
  187. beep
  188. message "\bThe modem didn't respond to initialization"
  189. message "\bstring.  Check the modem."
  190. goto aborted
  191.  
  192. label nodialtone
  193. beep
  194. message "\bThe modem could not detect a dialtone."
  195. message "\bCheck the phone line."
  196. goto aborted
  197.  
  198. label phonebusy
  199. flush
  200. message "\bThe number $phone is busy."
  201. if $busygo eq "go" goto redial
  202. on restart goto busygo
  203. beep
  204. message "\bClick "Restart" to keep trying, "OK" to quit."
  205. ask junk
  206. return 0
  207.  
  208. label busygo
  209. on restart goto restart
  210. set busygo "go"
  211. flush
  212. label redial
  213. do syncmodem
  214. goto dial
  215.  
  216. label nocarrier
  217. beep
  218. message "\bThe modem could not establish a connection."
  219. message "\bMake sure there is a modem on the other end."
  220. goto aborted
  221.  
  222. label dialtimeout
  223. message "\bThe modem or SLIP server isn't responding."
  224. message "\bTry dialing manually to make sure the modem"
  225. message "\band SLIP server are OK."
  226. goto aborted
  227.  
  228. label baduser
  229. beep
  230. message "\bThe SLIP server won't accept a username."
  231. message "\bTry dialing manually to make sure the SLIP"
  232. message "\bserver is OK."
  233. goto hangup
  234.  
  235. label cantlogin
  236. beep
  237. message "\bLogin to SLIP server failed, check username"
  238. message "\band password."
  239. goto hangup
  240.  
  241. label cantsetterm
  242. beep
  243. message "\bCan't set terminal line for SLIP operation."
  244. goto hangup
  245.  
  246. label cantstartslip
  247. beep
  248. message "\bCan't put server into SLIP mode."
  249. goto hangup
  250.  
  251. # General back-end for bailing out.
  252.  
  253. label hangup
  254. do disconnect
  255. # fallthrough into aborted
  256.  
  257. label aborted
  258. message "\bScript aborted!"
  259. message "\bClick "OK" to quit, "Restart" to retry."
  260. # This activates the OK button.
  261. ask junk
  262. flush
  263. return 0
  264.  
  265. # Restart procedure.
  266. # This label is entered when you click the restart button in the
  267. # connection dialog. We try to force the modem to hang up, then we go back
  268. # to the start of the script.
  269.  
  270. label restart
  271. do disconnect
  272. message "\bScript restarted."
  273. goto startup
  274.  
  275. # Disconnect procedure. The "disconect" procedure is called by MacSLIP
  276. # when the "Disconnect" button is clicked. This procedure escapes the
  277. # modem into command mode and hangs up the phone. The +++ escape sequence
  278. # is surrounded by delays that some modems require.
  279.  
  280. label disconnect
  281. send "\d\d+++\d\dATH\r\d\d"
  282. do syncmodem
  283. return 1
  284.  
  285. # Alternate disconnect procedure for modems that drop into command mode
  286. # when DTR is dropped. You may want to try this alternate disconnect
  287. # procedure if the one above doesn't work for your modem. Just swap the
  288. # labels to use this one instead of the one above.
  289.  
  290. label disconnect2
  291. dtr off
  292. delay 3
  293. send "ATH\r"
  294. dtr on
  295. flush
  296. return 1
  297.  
  298. # Attempt to sync up with the modem, but don't wait forever.
  299. label syncmodem
  300. setcount 4 0
  301. flush
  302. label waitmodem2
  303. ifcountgt 4 2 return
  304. send "AT\r"
  305. {
  306.     ifmatch "OK" break
  307.     iftime 2 goto waitmodem2
  308. }
  309. flush
  310. return
  311.  
  312. # for Emacs
  313. #  Local Variables:
  314. #  tab-width: 4
  315. #  End:
  316.